package com.zyc.base.method.java;

import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.codegen.mybatis3.javamapper.elements.AbstractJavaMapperMethodGenerator;

import java.util.Set;
import java.util.TreeSet;

/**
 * @Author zyc
 * @Date 2019/4/17 10:55
 * @Description  增加按条件查询方法
 */
public class SelectByPrimaryKeySelectiveMethodGenerator extends
        AbstractJavaMapperMethodGenerator {

    private final String name ="selectByPrimaryKeySelective";

    private boolean isSimple;
    
    public SelectByPrimaryKeySelectiveMethodGenerator(boolean isSimple) {
        super();
        this.isSimple = isSimple;
    }

    @Override
    public void addInterfaceElements(Interface interfaze) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = new Method();
        method.setVisibility(JavaVisibility.PUBLIC);
        method.setName(name);
        FullyQualifiedJavaType parameterType;
        if (introspectedTable.getRules().generateRecordWithBLOBsClass()) {
            parameterType = new FullyQualifiedJavaType(introspectedTable
                    .getRecordWithBLOBsType());
        } else {
            parameterType = new FullyQualifiedJavaType(introspectedTable
                    .getBaseRecordType());
        }
        method.setReturnType(new FullyQualifiedJavaType("List<"+introspectedTable
                .getBaseRecordType()+">"));
        importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
        addMapperAnnotations(interfaze, method);
        context.getCommentGenerator().addGeneralMethodComment(method,
                introspectedTable);
        method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$
        if (context.getPlugins().clientSelectByPrimaryKeyMethodGenerated(
                method, interfaze, introspectedTable)) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }

    public void addMapperAnnotations(Interface interfaze, Method method) {
    }
}
